package com.wmm.unilt;

import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;

import java.io.IOException;

public class FastDFSUnilt {

    public static String uploadServer(String oldFileName,String hou, String newFilePath){

        String fileId = null;
        /* 2、把文件从web服务器上传到FastDFS */
        try {
            //加载配置文件
            ClientGlobal.initByProperties("config/fastdfs-client.properties");

            //创建tracker客户端
            TrackerClient trackerClient = new TrackerClient();
            //通过tracker客户端获取tracker的连接服务并返回
            TrackerServer trackerServer = trackerClient.getConnection();
            //声明storage服务
            StorageServer storageServer = null;
            //定义storage客户端
            StorageClient1 client = new StorageClient1(trackerServer, storageServer);

            //定义文件元信息
            NameValuePair[] list = new NameValuePair[1];
            list[0] = new NameValuePair("fileName",oldFileName);

            fileId = client.upload_file1(newFilePath, hou, list);

            trackerServer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return fileId;
    }
}
